<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>编辑权限</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../static/css/font.css">
		<link rel="stylesheet" href="../../../static/css/weadmin.css">
  </head>
  <body>
    <div class="weadmin-body">
        <form class="layui-form" action="/admin/user/authlist//editauth" method="post">
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="we-red">*</span>权限名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="authname" name="authname" required="" lay-verify="required"
                  autocomplete="off" value="<%- auth.authname %>" class="layui-input" >
              </div>
          </div>
        <div class="layui-form-item">
            <label class="layui-form-label">权限地址</label>
            <div class="layui-input-block">
              <input type="text" autocomplete="off" class="layui-input" id="authurl" name="authurl" value="<%- auth.authurl %>">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">权限说明</label>
            <div class="layui-input-block">
              <input type="text" autocomplete="off" class="layui-input" id="brief" name="brief" value="<%- auth.brief %>">
            </div>
          </div>
         <div class="layui-form-item"  >
            <label for="username" class="layui-form-label">
            </label>
            <div class="layui-input-inline" style="display:none">
                <input type="text" id="authid" name="authid" required="" lay-verify="required"
                autocomplete="off" value="<%- auth.id %>" class="layui-input" >
            </div>
         </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="add">
                  修改权限
              </button>
          </div>
      </form>
    </div>
		<script src="../../../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript">
    	layui.extend({
				admin: '{/}../../../static/js/admin'
			});
	    layui.use(['form','layer','admin','jquery'], function(){
	      var form = layui.form,
	      	admin = layui.admin,
	      	layer = layui.layer;
          var $ = layui.jquery;

          $('#authname,#authurl').change(function(){
            let httpUrl = '/admin/user/authlist/testing'
            let that = this
            $.post(httpUrl,{
              authname:$('#authname').val(),
              authurl:$("#authurl").val()
            }).then(function(res){
              console.log(res)
              if(res.state == 'fail'){
                layer.msg(res.content,{
                icon: 2,
              })
              }
            })
          })


          //监听提交
          form.on('submit(add)', function(data){
            console.log(data);
            $.ajax({
              url:"/admin/user/authlist//editauth",
              method:"post",
              data:data.field
            }).then(function(res){ //提交后
              //发异步，把数据提交给nodejs
            layer.alert("修改成功", {icon: 6},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
                //修改成功后刷新页面
                parent.location.reload();
            });
            })
            return false;
          });
        });
    </script>
  </body>

</html>